<?php

class M_common extends CI_Model
{

    private $tableName;

    //获取数据带分页
    public function getListByPage($table, $w_str = '', $filed = '*', $w_order = '', $p = '1', $links = '?', $pageSize = '20')
    {
        $this->tableName = $this->db->dbprefix . $table;
        $rs = $this->M_sql->_getPage($this->tableName, $w_str, $filed, $w_order, $p, $links, $pageSize);
        return $rs;
    }

    //取一条数据
    public function getOneByWhere($table, $data, $filed = '*', $order = '')
    {
        $this->tableName = $this->db->dbprefix . $table;
        $rs = '';
        if ($data) {
            $rs = $this->M_sql->getOneByWhere($this->tableName, $data, $filed, $order);
        }
        return $rs;
    }

    //添加、修改
    public function updateTableValue($table, $data, $where = '')
    {
        $this->tableName = $this->db->dbprefix . $table;
        $rs = '';
        if ($where) {
            $rs = $this->M_sql->updateToTable($this->tableName, $data, $where);
        } else {
            $rs = $this->M_sql->addToTable($this->tableName, $data);
        }
        return $rs;
    }

    //删除数据
    public function delTableValue($table, $data = '')
    {
        $this->tableName = $this->db->dbprefix . $table;
        $rs = '';
        if ($data) {
            $rs = $this->M_sql->delFromTable($this->tableName, $data);
        }
        return $rs;
    }

    /**
     * 搜索数据
     * @param string $table 表名
     * @param array  $data 条件
     * @param string $filed 字段
     * @param string $order 排序
     * @param string $limit 记录数
     * @return array
     */
    public function getTableValue($table, $data = '', $filed = '*', $order = '', $limit = '')
    {
        $this->tableName = $this->db->dbprefix . $table;
        $rs = $this->M_sql->_getWhere($this->tableName, $data, $filed, $order, $limit);
        return $rs;
    }

    //统计
    public function getTableNums($table, $w_str = '', $filed = '*')
    {
        $this->tableName = $this->db->dbprefix . $table;
        $rs = $this->M_sql->_getNums($this->tableName, $w_str, $filed);
        return $rs;
    }

    //执行sql语句
    public function querySql($sql)
    {
        $query = $this->db->query($sql);
        return $query->result_array();
    }

}

?>
